package com.xncoding.trans.hannder;

import com.xncoding.trans.enums.RedisCacheEnums;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.List;
/**
 * 缓存提供者
 * @CreateAt: 2023-11-3 11:28:42
 * @ModifyAt: 2023-11-3 11:28:42
 * @Version 1.0
 */
@Component
@AllArgsConstructor
@Slf4j
public class RedisCacheProvider {
    private List<RedisCacheHandler> handlers;
    public RedisCacheHandler apply(RedisCacheEnums type) {
        RedisCacheHandler redisCacheHandler = handlers.stream().filter(x -> x.support(type)).findFirst().orElse(null);
        Assert.notNull(redisCacheHandler, "未找到对应的处理器");
        return redisCacheHandler;
    }
}
